using CNRegex.Entity;
using NHibernate.Linq;
using System.Linq;
using CNRegex.Entity.EntityEx;
using Project.Common;
using System;
using System.Collections.Generic;
using NHibernate;
using CNRegex.Enum;
namespace CNRegex.Dal.DataAccess {
	public partial class DalRegexUserBlogRecord 
	{
		private DalRegexUserBlog dalRegexUserBlog;
		private void Initialize()
		{

		}
		public override void Save(RegexUserBlogRecord entity)
		{
			ITransaction tx = this.Session.BeginTransaction();
			using (tx)
			{
				RegexUserBlog blog = dalRegexUserBlog.GetByID(entity.BlogID);
				if (entity.RecordType == (int)EnumRecordType.Click)
					blog.ClickCount = blog.ClickCount == null ? 1 : blog.ClickCount + 1;
				else
					blog.Recommend = blog.Recommend == null ? 1 : blog.Recommend + 1;
				dalRegexUserBlog.Save(blog);

				//get tody record.
				RegexUserBlogRecord recordEntity = base.ListBy(x => x.BlogID == entity.BlogID && x.RecordTime == entity.RecordTime && x.RecordType == entity.RecordType).FirstOrDefault();
				if (recordEntity == null)
				{
					entity.Times = 1;
					base.Save(entity);
				}
				else
				{
					recordEntity.Times = recordEntity.Times + 1;
					base.SaveOrUpdate(recordEntity);
				}
				tx.Commit();
			}
		}
	}
}
		